package com.imooc.diners.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.commons.dto.DinersDTO;
import com.imooc.commons.model.domain.ResultInfo;
import com.imooc.commons.model.vo.ShortDinerInfo;
import com.imooc.commons.utils.ResultInfoUtil;
import com.imooc.diners.service.DinersService;

/**
 * \* @author: bear
 * \* Date: 2021-07-11-17:07
 * \* describe:
 */
@RestController
public class DinersController {

	@Resource
	private DinersService dinersService;
	@Resource
	private HttpServletRequest request;

	@GetMapping("signin")
	public ResultInfo signIn(String username,String password){
		return dinersService.signIn(username,password,request.getServletPath());
	}

	/**
	 * 注册
	 *
	 * @param dinersDTO
	 * @return
	 */
	@PostMapping("register")
	public ResultInfo register(@RequestBody DinersDTO dinersDTO) {
		return dinersService.register(dinersDTO, request.getServletPath());
	}

	/**
	 * 校验手机号是否已注册
	 *
	 * @param phone
	 * @return
	 */
	@GetMapping("checkPhone")
	public ResultInfo checkPhone(String phone) {
		dinersService.checkPhoneIsRegistered(phone);
		return ResultInfoUtil.buildSuccess(request.getServletPath());
	}

	@GetMapping("findByIds")
	public ResultInfo<List<ShortDinerInfo>> findByIds(String ids){
		List<ShortDinerInfo> byIds = dinersService.findByIds(ids);
		return ResultInfoUtil.buildSuccess(request.getServletPath(),byIds);
	}

}
